#include "Composite.h"
#include <algorithm>
#include <iostream>

Composite::Composite(std::string _name)
	: Component(_name)
{

}

Composite::~Composite()
{

}

void Composite::Print()
{
	ShowName();
	std::vector<Component*>::iterator iter = m_comVec.begin();
	for(; iter != m_comVec.end(); ++iter)
	{
		(*iter)->Print();
	}
}

void Composite::Add(Component* cmp)
{
	if (find(m_comVec.begin(), m_comVec.end(), cmp) == m_comVec.end())
	{
		m_comVec.push_back(cmp);
	}
}

void Composite::Remove(Component* cmp)
{
	std::vector<Component*>::iterator iter = find(m_comVec.begin(), m_comVec.end(), cmp);
	if (iter != m_comVec.end())
	{
		m_comVec.erase(iter);
	}
}

Component* Composite::GetChild(int nIndex)
{
	if (m_comVec.size() >= nIndex)
	{
		return NULL;
	}

	return m_comVec[nIndex];
}